package View;

import javax.swing.*;

import Model.Game;
import Model.Tile;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.IOException;


/** This class is an extension of JPanel. When called, it presents the map screen,
 * i.e. WELCOME TO MULE
 * @author Josh Weinflash
 *
 */

public class MapScreen extends JPanel {

	private static final long serialVersionUID = 1L;
	public Label label1;
	public JLabel label2;
	public Game game;
	public int xpointer;
	public int ypointer;
	
	/** 
	 * @author Matt Miller
	 * Create main game screen (no functionality)
	 * @throws IOException 
	 * @PARAM this function accepts no parameters
	 * 
	 * this screen is the screen shown immediately before the start of the game
	 */
	
	public MapScreen(Game g) throws IOException 
	{
		setBackground(Color.WHITE);
		GridLayout myGridLayout = new GridLayout(5, 9, 0, 0);
		setLayout(myGridLayout);
		setPreferredSize(new Dimension(1200, 800));
		game = g;
        Tile[] gameTiles = game.getMap().getTileArray();
        for(int i = 0; i < gameTiles.length; i++) {
        	add(new TilePanel(gameTiles[i]));
        }
       
	}
	
	
	/**
	 * Updates the MapScreen
	 * @throws IOException 
	 */
	public void refresh() throws IOException {
		removeAll();
		GridLayout myGridLayout = new GridLayout(5,9,0,0);
		setLayout(myGridLayout);
		Tile[] gameTiles = game.getMap().getTileArray();
        for(int i = 0; i < gameTiles.length; i++) {
        	add(new TilePanel(gameTiles[i]));
        }
        repaint();
	}
		
}